package com.advanced.collectionAndGeneric_1;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * ArrayListSort--使用 ArrayList 类存储从控制台上录入的数据
 * ，直到输入 0 为止，然后用此类来实现冒泡排序。
 *
 * @author: Jovi
 * @createTime: 2017-05-17 14:03
 **/
public class ArrayListSort {

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        int num = 0;
        /* reserve the value */
        do {
            System.out.println("请输入一个整数（输入0结束）：");
            num = sc.nextInt();
            list.add(num);
        } while (num != 0);
        System.out.println("结束输入");
        /* sort */
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = 0; j < list.size()-i-1; j++) {
                if (list.get(j) > list.get(j + 1)) {
                    /* exchange*/
                    Integer temp = list.get(j);
                    list.set(j, list.get(j + 1));
                    list.set(j + 1, temp);
                }
            }
        }
        System.out.println("The sorted result is: ");
        for (Integer integer : list) {
            System.out.println(integer.intValue() + " ");
        }
        System.out.println(4.015 * 100.0);
    }
}
